package lc;

import java.util.Arrays;

//
//[[".",".",".",".","5",".",".","1","."],[".","4",".","3",".",".",".",".","."],[".",".",".",".",".","3",".",".","1"],["8",".",".",".",".",".",".","2","."],[".",".","2",".","7",".",".",".","."],[".","1","5",".",".",".",".",".","."],[".",".",".",".",".","2",".",".","."],[".","2",".","9",".",".",".",".","."],[".",".","4",".",".",".",".",".","."]]
//
public class lc36 {
    public static void main(String[] args) {
        int[] a = new int[1];
        isValidSudoku(new char[][]{{'.','.','.','.','5','.','.','1','.'},{'.','4','.','3','.','.','.','.','.'},{'.','.','.','.','.','3','.','.','1'}});
    }
        public static boolean isValidSudoku(char[][] board) {
            int[] help = new int[10];
            for(int i = 0; i < 9; i++){
                for(int j = 0; j < 9; j++){
                    if(board[i][j] == '.') continue;
                    help[board[i][j] - '0']++;
                    if(help[board[i][j] - '0'] > 1) return false;
                }
                Arrays.fill(help, 0);
            }
            for(int i = 0; i < 9; i++){
                for(int j = 0; j < 9; j++){
                    if(board[j][i] == '.') continue;
                    help[board[j][i] - '0']++;
                    if(help[board[j][i] - '0'] > 1) return false;
                }
                Arrays.fill(help, 0);
            }
            for(int i = 0; i < 3; i++){
                for(int j = 0; j < 3; j++){
                    for(int a = i * 3; a < i * 3 + 3; a++){
                        for(int b = j * 3; b < j * 3 + 3; b++){
                            if(board[a][b] == '.') continue;
                            help[board[a][b] - '0']++;
                            if(help[board[a][b] - '0'] > 1) return false;
                        }
                        Arrays.fill(help, 0);
                    }
                }
            }
            return true;
        }

}
